%option c++
%option yylineno
%option noyywrap
%{
#include "parser.h"
int cur_line_num = 1;
void init_scanner();
void lex_error(char* msg, int line);
%}

/* Definitions, note: \042 is '"' */
INTEGER             ([+-]*[0-9]+)
UNTERM_STRING       (\042[^\042\n]*)
STRING              (\042[^\042\n]*\042)
IDENTIFIER          ([_a-zA-Z][_a-zA-Z0-9]*)
OPERATOR            ([+*-/%=,;!<>(){}])
SINGLE_COMMENT1     (";"[^\n]*)

%%

[\n]                { cur_line_num++;                       }
[ \t\r\a\f]+          { /* ignore all spaces */               }
{SINGLE_COMMENT1}   { /* skip for single line comment */    }

"("                { return makeToken(cur_line_num,0,Tok_LP,0,0);      }
")"                { return makeToken(cur_line_num,0,Tok_RP,0,0);      }
"<="                { return makeToken(cur_line_num,0,Tok_LE,0,0);      }
">="                { return makeToken(cur_line_num,0,Tok_GE,0,0);      }
"="                { return makeToken(cur_line_num,0,Tok_EQ,0,0);      }
">"                { return makeToken(cur_line_num,0,Tok_GT,0,0);      }
"<"                { return makeToken(cur_line_num,0,Tok_LT,0,0);      }
"+"                { return makeToken(cur_line_num,0,Tok_Symbol,0,0);      }
"-"              { return makeToken(cur_line_num,0,Tok_Symbol,0,0);      }
"*"               { return makeToken(cur_line_num,0,Tok_Symbol,0,0);      }
"/"             { return makeToken(cur_line_num,0,Tok_Symbol,0,0);      }
"%"                { return makeToken(cur_line_num,0,Tok_Symbol,0,0);      }



{INTEGER}           { return makeToken(cur_line_num,0,Tok_Symbol,yytext,yyleng);      }
{STRING}            { return makeToken(cur_line_num,0,Tok_String,yytext,yyleng);      }
{IDENTIFIER}        { return makeToken(cur_line_num,0,Tok_Symbol,yytext,yyleng);      }

<<EOF>>             { return 0; }

{UNTERM_STRING}     { lex_error("Unterminated string constant", cur_line_num);  }
.                   { lex_error("Unrecognized character", cur_line_num);        }

%%


